home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
Book Chapters
/
11 - Porting
/
Sample Code
/
FindFile.c
< prev
next >
Wrap
Text File
|
1995-03-28
|
2KB
|
78 lines
/************************************************************************************
* *
* FindFile.c *
* *
* ©1995 Douglas Grounds. All Rights Reserved. *
* *
* This file contains a function to find a file based on vRefNum, dirId and name, *
* or by name alone (full or relative path). *
* *
************************************************************************************/
#include <Dialogs.h>
#include <Files.h>
#include <StandardFile.h>
#include <stdio.h>
#include <string.h>
#include <Strings.h>
#include <Types.h>
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#include "FindFile.h"
#define kFindFileAlertId 128
/******************************************************
* findFile. *
* *
* Finds a file by itself, or with some assistance. *
* To find a file with full path name, send in 0 for *
* vRefNum and dirId. *
******************************************************/
Boolean findFile (short vRefNum, long dirId, char *fileName, FSSpec *foundFile)
{
FSSpec searchFile;
Str255 pascalVersion;
SFTypeList myTypes;
StandardFileReply reply;
OSErr err;
strcpy((char *)pascalVersion, fileName);
c2pstr((char *)pascalVersion); // Make look different on different compilers.
err = FSMakeFSSpec(vRefNum, dirId, pascalVersion, &searchFile);
if (err != noErr)
{
sprintf((char *)pascalVersion, "The file named “%s” could not be found. Would you like to look for it?",
foundFile);
c2pstr((char *)pascalVersion);
InitCursor();
ParamText(pascalVersion, "\p", "\p", "\p");
if (Alert(kFindFileAlertId, NULL) == 1)
{
StandardGetFile(NULL, 1, myTypes, &reply);
if (reply.sfGood == FALSE)
return FALSE;
else
{
*foundFile = reply.sfFile;
return TRUE;
}
}
}
*foundFile = searchFile;
return TRUE;
}